package com.ruyuan.engine.utils;
import com.ruyuan.engine.pojo.RuleEventExecuteParam;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class CombinationServiceUtils {

    public static String GenSearchCombinationSql(String userId, RuleEventExecuteParam ruleEventExecuteParam) {
        //完成SQL的拼接
        String sql = "select userNo,count(1) as userCnt from clientLogDetail\n" +
                "where userNo='"+userId+"' and eventId = '"+ruleEventExecuteParam.getEventId()+"' and detailTime >= "+ruleEventExecuteParam.getEventStartTime()+"\n" +
                "and detailTime <= "+ruleEventExecuteParam.getEventEndTime()+"";
        String sql3 = "group by userNo";

        //拼接属性的条件
        HashMap<String, String> properties = ruleEventExecuteParam.getProperties();
        Set<Map.Entry<String, String>> entries = properties.entrySet();
        StringBuffer stringBuffer = new StringBuffer();
        for(Map.Entry<String,String> entry:entries) {
            stringBuffer.append("\n and properties['"+entry.getKey()+"'] = '"+entry.getValue()+"'");
        }
        return sql + stringBuffer.toString() + sql3;
    }
}
